import axios from 'axios'
import { Message } from 'element-ui'

const server = axios.create({
  baseURL: 'http://itsui.top',
  timeout: 5000,
})

//请求拦截器
server.interceptors.request.use(
  (config) => {
    // 带上token
    config.headers.Authorization = sessionStorage.getItem('token')
    return config
  },
  (error) => {
    console.log(error)
    return Promise.reject(error)
  },
)
//响应拦截器
server.interceptors.response.use(
  (response) => {
    return response
  },
  (error) => {
    console.log(error)
    Message.error('请求超时，请稍后再试')
    return Promise.reject(error)
  },
)

export default server
